// index.js

Page({
  data: {

  },
  onShow() {
    this.setTabBarIndex()
  },
  onHide() {
    wx.pageScrollTo({ scrollTop: 0 })
  },
  setTabBarIndex() {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0
      })
    } else {
      console.log('未获取到getTabBar()');
    }
  },
  onPageScroll(e) {
    let scrollTop = e.scrollTop
    let val = scrollTop > 300 ? true : false
    this.setCustomTab(val)
  },
  setCustomTab(val) {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      let list = this.getTabBar().data.list
      if (list[0].scrollTop === val) return
      list[0].scrollTop = val
      this.getTabBar().setData({ list })
    }
  },
  scrolleTopFun() {
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 300,
    })
  },
})
